import { IUserItem, getUserList } from '@/fetch/user'
import { defineStore } from 'pinia'

export const useUser = defineStore('user', {
  persist: true,
  state: () => {
    return {
      userList: [] as IUserItem[],
      currentUser: {} as IUserItem,
      token: ''
    }
  },
  actions: {
    async getUserList() {
      const { data: { data } } = await getUserList()
      this.userList = data
    },
    setUser(user: IUserItem) {
      this.currentUser = user
    },
    setToken(token: string) {
      this.token = token
    },
    delToken() {
      this.token = ''
    }
  }
})